<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <button id="btn">获取新歌</button>
  <ul id="ul">
    <!-- <li>test</li> -->
  </ul>


  <script>
    let btn = document.getElementById('btn')
    btn.addEventListener('click', () => {
      // 发一个http请求
      let xhr = new XMLHttpRequest()
      xhr.open('GET', 'http://192.168.31.26:3000/top/song?type=7', true)
      xhr.onreadystatechange = () => {
        if (xhr.readyState === 4 && xhr.status === 200) {
          const result = JSON.parse(xhr.responseText).data
          console.log(result);
          for (let i = 0; i < result.length; i++) {
            // result[i].name
            const li = document.createElement('li')
            li.innerText = result[i].name
            document.getElementById('ul').appendChild(li)
          }

        }
      }
      xhr.send()
      
    })

  </script>
</body>
</html>